package config;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

//单例模式
public class ConfigReader {
    private static ConfigReader instance;
    private Properties properties;

    private ConfigReader() {
        properties = new Properties();
        try (InputStream inputStream = ConfigReader.class.getClassLoader().getResourceAsStream("config.properties")) {
            if (inputStream == null) {
                throw new IOException("config.properties 文件没有找到");
            }
            properties.load(inputStream);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static ConfigReader getInstance() {
        if (instance == null) {
            instance = new ConfigReader();
        }
        return instance;
    }

    public String getLogType() {
        return properties.getProperty("logType");
    }

    public String getLogFormat() {
        return properties.getProperty("logFormat");
    }

    public String getFileLogPath() {
        return properties.getProperty("fileLogPath");
    }

    public String getDatabaseUrl() {
        return properties.getProperty("databaseUrl");
    }

    public String getDatabaseUser() {
        return properties.getProperty("databaseUser");
    }

    public String getDatabasePassword() {
        return properties.getProperty("databasePassword");
    }

    public String getLogLevel() {
        return properties.getProperty("logLevel", "INFO");
    }
}
